import { lastValueFrom } from "rxjs";
import { Injectable } from "@nestjs/common";

import { EmailRpcInterface, postEmailTouchRpcDto, EmailTouchGateway, ENUM_APP, postEmailTouchRpcRes } from "qqlx-core";

import { BusRpc } from "./app.droplet-bus";
import { RpcWaiting } from "./rpc.response";
import { RpcConnection } from "./com.connection";

@Injectable()
export class TouchRpc extends RpcConnection implements EmailRpcInterface<{}> {
  constructor(readonly BusRpc: BusRpc) {
    super(BusRpc, ENUM_APP.DROPLET_TOUCH);
  }

  @RpcWaiting(`${EmailTouchGateway.path}/post`)
  async postEmail(dto: postEmailTouchRpcDto) {
    const ob = this.CLIENT.send(`${EmailTouchGateway.path}/post`, dto);
    return lastValueFrom<postEmailTouchRpcRes>(ob);
  }
}
